<template>
  <div>
    <h3>商品详情页面</h3>

    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(item, index) in gallery" :key="index">
        <img class="banner" :src="item.img_url" alt="" />
      </van-swipe-item>
    </van-swipe>

    <div class="swiper-b">
      <div class="item">30天无忧退货</div>
      <div class="item">48小时快速退款</div>
      <div class="item">满88元免邮费</div>
    </div>
    <div class="goods-info">
      <div class="c">
        <p>{{ info.name }}</p>
        <p>{{ info.goods_brief }}</p>
        <p>￥{{ info.retail_price }}</p>
        <div v-if="brand.name" class="brand">
          <p>{{ brand.name }}</p>
        </div>
      </div>
    </div>
    <div @click="showType" class="section-nav">
      <div>请选择规格数量</div>
      <div></div>
    </div>

    <div v-if="attribute.length != 0" class="attribute">
      <div class="head">商品参数</div>
      <div v-for="(item, index) in attribute" :key="index" class="item">
        <div>{{ item.name }}</div>
        <div>{{ item.value }}</div>
      </div>
    </div>

    <div v-html="goods_desc" class="desc"></div>

    <!-- 常见问题 -->
    <div class="common-problem">
      <div class="h">
        <div class="line"></div>
        <div class="title">常见问题</div>
        <div class="line"></div>
      </div>
      <div class="b">
        <div class="item" v-for="(item, index) in issueList" :key="index">
          <div class="question-box">
            <div class="spot"></div>
            <div class="question">{{ item.question }}</div>
          </div>
          <div class="answer">
            {{ item.answer }}
          </div>
        </div>
      </div>
    </div>

    <!-- 大家都在看 -->

    <div class="common-problem">
      <div class="h">
        <div class="line"></div>
        <div class="title">大家都在看</div>
        <div class="line"></div>
      </div>
      <div class="sublist">
        <router-link
          replace
          tag="div"
          :to="`/category/list/info?id=${subitem.id}`"
          v-for="(subitem, subindex) in productList"
          :key="subindex"
        >
          <img :src="subitem.list_pic_url" alt="" />
          <p>{{ subitem.name }}</p>
          <p>￥{{ subitem.retail_price }}</p>
        </router-link>
      </div>
    </div>

    <!-- 大家都在看 -->
    <div class="bottom-fixed">
      <div>
        <div class="collect" :class="[collectFlag ? 'active' : '']"></div>
      </div>
      <div>
        <div class="car">
          <span>
            {{ allnumber }}
          </span>
          <img src="@/assets/images/ic_menu_shoping_nor.png" alt="" />
        </div>
      </div>
      <div>立即购买</div>
      <div>加入购物车</div>
    </div>

    <van-icon
      name="star-o"
      :color="isCollected == true ? 'red' : ''"
      @click="collectedEvents"
    />
  </div>
</template>

<script>
import { detailaction, addcollect } from "@/api/category/list/info";
export default {
  data() {
    return {
      allnumber: 0,
      isCollected: false,
      collectFlag: false,
      gallery: [],
      attribute: [],
      info: {},
      brand: {},
      goods_desc: "",
      issueList: [],
      productList: [],
    };
  },
  created() {
    // this.userInfo = localStorage.getItem("userInfo");
    // console.log(userInfo);
    console.log(this.$route.query.id);
    this.init();
  },
  watch: {
    $route: function (to, from) {
      // console.log("to", to);
      this.id = to.query.id;

      //  this.goodsDetail();
    },
  },
  methods: {
    init() {
      detailaction({
        id: this.$route.query.id,

        openId: localStorage.getItem("openId"),
      }).then((res) => {
        console.log(res);
        this.gallery = res.data.gallery;
        this.isCollected = res.data.collected;
        this.attribute = res.data.attribute;
        this.info = res.data.info;
        this.brand = res.data.brand;
        this.goods_desc = res.data.info.goods_desc;
        this.issueList = res.data.issue;
        this.productList = res.data.productList;
      });
    },

    collectedEvents() {
      addcollect({
        goodsId: this.$route.query.id,

        openId: localStorage.getItem("openId"),
      }).then((res) => {
        console.log(res);

        this.isCollected = !this.isCollected;
      });
    },

    showType() {
      console.log("hi");
    },
  },
  computed: {},
};
</script>
<style scoped lang='scss'>
.banner {
  width: 100%;
  height: 375px;
}

.swiper-b {
  width: 100%;
  height: 36px;
  margin: 0 auto;
  background: #f4f4f4; // padding: 0 31.25px;
  display: flex;
  align-items: center;
  justify-content: space-between;

  div {
    background: url("http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/servicePolicyRed-518d32d74b.png")
      0 center no-repeat;
    background-size: 10px;
    padding-left: 15px;
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #666;
  }
}

.goods-info {
  width: 100%;
  height: 150px;
  background: #fff;
  margin: 0 auto;
  border-bottom: 1px solid #f4f4f4;

  .c {
    height: 100%;

    p {
      display: block;
      text-align: center;
    }

    p:nth-child(1) {
      font-size: 20px;
      padding: 10px;
    }

    p:nth-child(2) {
      margin-bottom: 12px;
      font-size: 12px;
      color: #999;
    }

    p:nth-child(3) {
      margin-top: 4px;
      font-size: 16px;
      color: #b4282d;
    }

    .brand {
      margin-top: 12px;
      text-align: center;

      p {
        display: inline-block;
        color: #b1a279;
        font-size: 10px;
        padding: 2px 14px;
        border: 1px solid #b1a279;
      }
    }
  }
}

.section-nav {
  height: 54px;
  background: #fff;
  margin-bottom: 10px;
  padding: 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  div:nth-child(2) {
    width: 26px;
    height: 26px;
    background: url()
      no-repeat;
    // background: url("~@/assets/images/address_right.png") no-repeat;
    background-size: 100% 100%;
  }
}

.attribute {
  padding: 10px 15px;
  background: #fff;
  margin-bottom: 10px;

  .head {
    font-size: 19px;
    padding: 10px 0;
  }

  .item {
    display: flex;
    background: #f7f7f7;
    padding: 10px 0;
    margin: 10px;

    div:nth-child(1) {
      width: 72px;
      font-size: 12px;
      color: #999;
    }

    div:nth-child(2) {
      flex: 1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}

.desc {
  width: 100%;

  ::v-deep p {
    margin: 0;
    padding: 0;
  }
  ::v-deep img {
    display: block;
    width: 100%;
    // width: 375px;
  }
}

.common-problem {
  margin-bottom: 55px;
  text-align: left;

  .h {
    padding: 16px 0;
    background: #fff;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;

    .line {
      display: inline-block;
      height: 1px;
      width: 50px;
      background: #ccc;
    }

    .title {
      padding: 0 12px;
      background: #fff;
    }
  }

  .b {
    padding: 0px 15px;
    background: #fff;

    .item {
      padding-bottom: 12px;

      .question-box {
        display: flex;

        .spot {
          height: 4px;
          width: 4px;
          background: #b4282d;
          border-radius: 50%;
          margin-top: 5px;
        }

        .question {
          line-height: 15px;
          padding-left: 4px;
          display: block;
          font-size: 13px;
          padding-bottom: 8px;
          color: #303030;
        }
      }

      .answer {
        line-height: 20px;
        padding-left: 8px;
        font-size: 13px;
        color: #787878;
      }
    }
  }

  .sublist {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    width: 365px;
    margin: 0 auto;

    div {
      width: 180px;
      background: #fff;
      margin-bottom: 5px;
      padding-bottom: 5px;

      img {
        display: block;
        width: 150px;
        height: 150px;
        margin: 0 auto;
      }

      p {
        margin-bottom: 2px;
        text-indent: 1em;
      }

      p:nth-child(2) {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        width: 98%;
      }

      p:nth-child(3) {
        color: #9c3232;
      }
    }

    .last {
      display: block;
      width: 150px;
      height: 150px;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      flex-wrap: wrap;

      p {
        height: 16px;
        width: 100%;
        line-height: 16px;
        color: #333;
        font-size: 16px;
        text-align: center;
      }

      .icon {
        display: inline-block;
        width: 35px;
        height: 35px;
        // background: url("~@/assets/images/rightbig.png") no-repeat;
        background-size: 100% 100%;
        margin-top: 30px;
      }
    }

    div:nth-child(2n) {
      margin-left: 5px;
    }
  }
}

.bottom-fixed {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 50px;
  display: flex;
  background: #fff;
  z-index: 10;

  div:nth-child(1) {
    height: 50px;
    width: 80px;
    border: 1px solid #f4f4f4;
    display: flex;
    align-items: center;
    justify-content: center;

    .collect {
      display: block;
      height: 22px;
      width: 22px;
      background: url("../../../static/images/~@/assets/images/icon_collect.png")
        no-repeat;
      background-size: 100% 100%;
    }

    .collect.active {
      display: block;
      height: 22px;
      width: 22px;
      background: url("../../../static/images/~@/assets/images/icon_collect_checked.png")
        no-repeat;
      background-size: 100% 100%;
    }
  }

  div:nth-child(2) {
    height: 50px;
    width: 80px;
    border: 1px solid #f4f4f4;
    display: flex;
    align-items: center;
    justify-content: center;

    .car {
      position: relative;
      height: 30px;
      width: 30px;

      span {
        height: 14px;
        width: 14px;
        z-index: 10;
        position: absolute;
        top: 0;
        right: 0;
        background: #b4282d;
        text-align: center;
        font-size: 10px;
        color: #fff;
        line-height: 14px;
        border-radius: 50%;
      }

      img {
        display: block;
        height: 22px;
        width: 22px;
        position: absolute;
        top: 5px;
        left: 0;
      }
    }
  }

  div:nth-child(3) {
    height: 50px;
    line-height: 48px;
    flex: 1;
    text-align: center;
    color: #333;
    border-top: 1px solid #f4f4f4;
    border-bottom: 1px solid #f4f4f4;
  }

  div:nth-child(4) {
    border: 1px solid #b4282d;
    background: #b4282d;
    float: left;
    height: 50px;
    line-height: 48px;
    flex: 1;
    text-align: center;
    color: #fff;
  }
}
</style>



